# Maintainer: Kyle Keen <keenerd@gmail.com>
# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Gabriel Souza Franco <Z2FicmllbGZyYW5jb3NvdXphQGdtYWlsLmNvbQ==>
# Contributor: Florian Pritz <bluewind@xinu.at>
# Contributor: Giuseppe Borzi <gborzi@ieee.org>
# Contributor: Brice Méalier <mealier_brice@yahoo.fr>
# Contributor: Michele Mocciola <mickele>

pkgname=opencascade
pkgver=7.6.3
pkgrel=3
epoch=1
pkgdesc='SDK intended for development of applications dealing with 3D CAD data'
arch=('loong64' 'x86_64')
url='https://www.opencascade.org'
license=('LGPL2.1' 'custom:LGPL-exception')
depends=(
  'ffmpeg4.4'
  'freeimage'
  'gl2ps'
  'intel-tbb'
  'tk'
  'vtk'
)
makedepends=(
  'git'
  'adios2'
  'boost'
  'cmake'
  'eigen'
  'gdal'
  'glew'
  'libharu'
  'liblas'
  'openvr'
  'pdal'
  'proj'
  'pugixml'
  'python'
  'python-mpi4py'
  'qt5-base'
  'rapidjson'
  'unixodbc'
  'utf8cpp'
)
_commit='b079fb9877ef64d4a8158a60fa157f59b096debb'
source=(
  "$pkgname::git+https://git.dev.opencascade.org/repos/occt.git#commit=$_commit"
  'opencascade.sh'
  'fix-install-dir-references.patch'
  'cmake-fix-variable.patch'
  'skip-license-installation.patch'
  'vtk9.patch'
  'opencascade-tbb-2021.patch'
  'ffmpeg4.4.patch'
  'vtk-6.2.patch::https://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=7f523af8'
)
sha512sums=('SKIP'
            'a7516028e55fd303dc1cfb61b75c9cb209d431d854b4d1c58f9c19df8ecee9d79da5c8745676c68a2de0980652de4c4d1c5a927c25db1e5146fb1f1f43c5906b'
            '826b8572eb298696b0005701bca5ad0406151ec7aa88cd53f9ffaf23a306003a48416b6d120dc5c7e3c14d290e9a15ba93943c4846b6fee8bdb06bd699904f79'
            'ad6ce2f52462989bd990b52fd5428f3e5cbd4fb15c38d92c0e0954e6afc3368fca961b92efead8e8957213352fb87a469e1bfaccaf14b484351acc0a0bc10485'
            'fd8499793b12e4e59420f63351fef9599c3976d307979beea2681b873a340ae673ba643a7060c74bec1dd4801954c99f8f1f1a8bcc3baa3db9cbfce32153675e'
            '2725df308f23f11faa664391174a4f21bec13328c7b33ba065bfd28988a4bd815c86849d8815fcdb8f6ed5dd1d7b1a38ded1675c1c08dec1276367fc571917c0'
            '1d6e0321d0b54caf0130b2c6f81dbbdc621913ffa1c38e464d9be65088085fc831ac69788393911a1dd269f4296c93d26c1706d262537912459eb795bc4f742b'
            'cb2c9602e7f18ab0543bb84f9f6cd5f759c0bf9de599fc25015fef4efd96d216c044250fc49bafa2d71de2a36e4ccd534416da1971d04f2c8f932751c0db6c50'
            '0f3ba616c840d972c8d0da620a607e685d44e00cf135924f381d9200bdc91ede8c3b542355123358f2cb554188580bb243cb5341596382b4ff5a404c66c8b6d2')
b2sums=('SKIP'
        'da9db038ed2348d2d7736505eda2f40fe52c836bcedb74d9f369cc53f7d40a330bd87d6aedd773863745cd46e4dbe5876acda2d2d60177f00d5db9cae4f1f102'
        'a56cedf43366d52a81301d653834942fb74a4feafb4ac57923448d42164f060f1874a2180688e482c0dac70a5ea1d2fb53d4410503f22626ff5d2bab405a352f'
        'bb98b2b53a9a97ae15a353a9dbcc6d92a97ddaa56af0610cefe9de3a4b84c4a6021d9396f7e270c1d379278df069dbf90f9771db64947e52d38ad36bc3c6f913'
        'da815c14ad3a8283c4f3cf41b6b19b40408798f64374b909c776f5ab22ee9ccfc2653c09b33c7b550a138007ff2b36b40d742c9fddc7c1ea499dfe58e59f57ea'
        'af240c6f9ba62f336f59caa7cff2bb40915137a02f5b03ee54fa17a5ef27d0411800aa981090a17b3d7c780835625bd4b263975eb100aa71fdc58eb1806916ea'
        '905d13cf39225c1148e215ad37ab601dfe649f3d4d66b099ae028cdf8fb2a92534e7b14361238566c295ae443a3a3dfeb5f69ab51987b952604eb53821fa92cd'
        '2a7861d4273344f62b7356f4a171d461e607a217f07e37fa869d24c6ffed7682948c8870bccf71e80bd8bbdeffcf32d74fb25d6a20c4344c4017618d1606f27d'
        '913993c78ef8afabca76ba45770a00507baa54d2b321a082f54357bb6cdadda1fe56de5e02c1f37b5b80188e3ef17993f0317838c2145e7d90566c648e6b77c3')

pkgver() {
  cd "$pkgname"
  git describe --tags | sed -e "s/^V//" -e "s/_/./g" -e "s/p/./"
}

prepare() {
  cd "$pkgname"

  patch -p1 -i ../fix-install-dir-references.patch
  patch -p1 -i ../cmake-fix-variable.patch
  #patch -p1 -i ../vtk9.patch # Fix build with VTK 9 https://gitlab.kitware.com/vtk/vtk/-/issues/18240
  #git cherry-pick -n 5e7632824302761b84cfceb5bfb2241d906d0eb4 # Fix build of FreeCAD
  patch -p1 -i ../skip-license-installation.patch
  patch -p1 -i ../opencascade-tbb-2021.patch # Fix build with TBB 2021
  patch -p1 -i ../ffmpeg4.4.patch # Use FFmpeg 4.4
  patch -p1 -i ../vtk-6.2.patch # Fix build with VTK 6.2
}

build() {
  cmake \
    -B build \
    -S "$pkgname" \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D BUILD_RELEASE_DISABLE_EXCEPTIONS=OFF \
    -D USE_FREEIMAGE=ON \
    -D USE_FFMPEG=ON \
    -D USE_VTK=ON \
    -D USE_RAPIDJSON=ON \
    -D USE_TBB=ON \
    -D 3RDPARTY_VTK_INCLUDE_DIR=/usr/include/vtk

  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  # environment variables (adapted from adm/templates/env.sh)
  install -vDm644 -t "$pkgdir/etc/profile.d" opencascade.sh

  # remove unnecessary shell scripts
  rm -v "$pkgdir/usr/bin/"*.sh

  cd "$pkgname"

  # licenses
  install -vDm755 -t "$pkgdir/usr/share/licenses/$pkgname" \
    LICENSE_LGPL_21.txt OCCT_LGPL_EXCEPTION.txt
}

# vim:set ts=2 sw=2 et:
